﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Vici.Mvc;
using Ss.Model;
using SSOtest.ServiceCenter;
namespace web
{
    public class Admin : BaseController
    {
        [View("Admin/login")]
        [Url("Admin/login")]
        public void Run()
        {
            ViewData["PageTitle"] = "SSOtest_测试登陆";
            if (Session["User"] != null)
                Redirect("~/admin/default");
        }
        [Url("Admin/CheckLogin")]
        public bool CheckLogin(string username, string userPwd)
        {
            User user = User.ReadFirst("LoginID=@LoginID", "@LoginID", username);
            if (user != null)
            {
                Session["User"] = user.LoginID;
                SSOtest.ServiceCenter.ServiceCenterSoapClient add = new ServiceCenterSoapClient();
                Session["toKen"] = add.AddNewToken(user.LoginID, user.PassWord, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Url.Host);
                Redirect("~/admin/default");
                return true;
            }
            Response.Write("<script>alert('账号不存在');</script>");
            Redirect("~/admin/login");
            return false;
        }
    }
}